package exercise;

public class EX06_OOP5 {	
	
	// setXxx메서드 작성법
	// 멤버 변수명이 name인 경우
	// public void setName(String name) {
	//   this.name = name;
	// }
	// public void set??? (##### ???) {
	//    this.??? = ???;
	// }
	
	// getXxx메서드 작성법
	// 멤버 변수명이 name인 경우
	// public String getName() {
	//    return this.name;
	// }
	// public ##### get???() {
	//    return this.???;
	// }

	public static void main(String[] args) {
		SungJukVO sj = new SungJukVO();
		// sj.name = "김태희";
		// 멤버변수가 private로 선언되었기 때문에 객체명.멤버변수명으로 사용 불가
		sj.setName("태희");
		// System.out.println(sj.name);
		System.out.println(sj.getName());
		
		RetangleVO2 rvo = new RetangleVO2();
		rvo.setWidth(4);
		rvo.setHeight(40);
		rvo.setColor("red");
		float area = RetangleService2.getArea(rvo.getWidth(), rvo.getHeight());
		System.out.println(area);
		
		FanVO2 fvo = new FanVO2();
		fvo.setSpeed(FanVO.FAST);
		fvo.setRadius(10);
		fvo.setOn(true);
		fvo.setColor("yellow");
		FanService2.toString(fvo);
		
		AccountVO2 avo = new AccountVO2();
		avo.setAid(1122);
		avo.setBalance(20000);
		avo.setInterestRate(4.5F);
		avo.setDateCreated("2013-11-08");
		AccountService2.withDraw(avo, 2500);
		AccountService2.withDraw(avo, 3000);
		float monthlyInterestRate =
				AccountService.getMonthlyInterestRate(avo.getInterestRate());
		String str = "잔액 : " + avo.getBalance() + " / 월간 이자율 : "
				+ monthlyInterestRate + " / 통장 개설날짜 : " + avo.getDateCreated();
		System.out.println(str);
		
		StockVO2 svo = new StockVO2();
		svo.setSname("경영기술");
		svo.setPreviousClosingPrice(1_000_000);
		svo.setCurrentPrice(750_000);
		float changePercent = StockService2.getChangePercent(
				svo.getPreviousClosingPrice(), svo.getCurrentPrice());
		System.out.println(changePercent + "%");
		
		
		
		
	} // main
} // EX06_OOP5	
	
class SungJukVO {
	private String name;
	int kor;
	int eng;
	int mat;
	
	// setter/getter 메서드 정의
	public void setName(String name) {
		this.name = name;
	}	// 멤버변수 name에 대한 setter
	public String getName() {
		return this.name;
	}	// 멤버변수 name에 대한 getter메서드
	
	public SungJukVO() {
	}
	public SungJukVO(String name, int kor, int eng, int mat){
		this.name = name;
	}
}	// SungJukVO

// #01
class RetangleVO2 {
	// 멤버변수
	private float width;
	private float height;
	private String color;
	
	// 생성자
	public RetangleVO2() {}
	public RetangleVO2(float width, float height, String color) {
		this.width = width;
		this.height = height;
		this.color = color;
	}
	
	// setter/getter
	public void setWidth(float width) {this.width = width;}
	public float getWidth() {return this.width;}
	
	public void setHeight(float height) {this.height = height;}
	public float getHeight() {return this.height;}
	
	public void setColor(String color) {this.color = color;}
	public String getColor() {return this.color;}	
	
} // RetangleVO2

class RetangleService2 {
	static float getArea(float width, float height) {
		return width * height;
	}
	static float getPerimeter(float width, float height) {
		return width * 2 + height * 2;
	}
} // RetangleService2

class FanVO2 {
	private static final int SLOW = 1;
	private static final int MEDIUM = 2;
	private static final int FAST = 3;
	private int speed;
	private boolean on;
	private float radius;
	private String color;
	
	public FanVO2() {
		speed = this.SLOW;
		on = false;
		radius = 5.0F;
		color = "blue";
	}
	public FanVO2(int speed, boolean on, float radius, String color){
		this.speed = speed;
		this.on = on;
		this.radius = radius;
		this.color = color;
	}
	
	public void setSpeed(int speed) {this.speed = speed;}
	public int getSpeed() {return this.speed;}
	
	public void setOn(boolean on) {this.on = on;}
	public boolean getOn() {return this.on;}
	
	public void setRadius(float radius) {this.radius = radius;}
	public float getRadius() {return this.radius;}
	
	public void setColor(String color) {this.color = color;}
	public String getColor() {return this.color;}
	
} // FanVO2

class FanService2 {
	static String toString(FanVO2 fvo) {
		String msg = "";
		if (fvo.getOn()) {
			msg = "속도 : " + fvo.getSpeed() + " / 색상 : " + fvo.getColor() + " / 지름 : "
					+ fvo.getRadius() + " / 작동중";
		} else {
			msg = "색상 : " + fvo.getColor() + " / 지름 : " + fvo.getRadius() + " / 꺼져있음";
		}
		return msg;
	}
}

// #03
class AccountVO2 {
	private int aid;
	private int balance;
	private float interestRate;
	private String dateCreated;

	public AccountVO2() {
		aid = 0;
		balance = 0;
		interestRate = 0;
	}

	public AccountVO2(int aid, int balance, float interestRate,	String dateCreated) {
		this.aid = aid;
		this.balance = balance;
		this.interestRate = interestRate;
		this.dateCreated = dateCreated;
	}
	
	public void setAid(int aid) {this.aid = aid;}
	public int getAid() {return this.aid;}
	
	public void setBalance(int balance) {this.balance = balance;}
	public int getBalance() {return this.balance;}
	
	public void setInterestRate(float interestRate) {this.interestRate = interestRate;}
	public float getInterestRate() {return this.interestRate;}
	
	public void setDateCreated(String dateCreated) {this.dateCreated = dateCreated;}
	public String getDateCreated() {return this.dateCreated;}

}

class AccountService2 {
	static float getMonthlyInterestRate(float interestRate) {
		return interestRate / 12;
	}

	static int withDraw(AccountVO2 avo, int money) {
		avo.setBalance(avo.getBalance() - money);
		System.out.println("인출 후 잔액: " + avo.getBalance());
		return avo.getBalance();
	}

	static int deposit(AccountVO2 avo, int money) {
		avo.setBalance(avo.getAid() + money);
		return avo.getBalance();
	}

}

class StockVO2 {
	private String sname;
	private int previousClosingPrice;
	private int currentPrice;

	public StockVO2() {
	}

	public StockVO2(String sname, int previousClosingPrice, int currentPrice) {
		this.sname = sname;
		this.previousClosingPrice = previousClosingPrice;
		this.currentPrice = currentPrice;
	}
	
	public void setSname(String sname) {this.sname = sname;}
	public String getSname() {return this.sname;}
	
	public void setPreviousClosingPrice(int previousClosingPrice) {
		this.previousClosingPrice = previousClosingPrice;
	}
	public int getPreviousClosingPrice() {return this.previousClosingPrice;}
	
	public void setCurrentPrice(int currentPrice) {this.currentPrice = currentPrice;}
	public int getCurrentPrice() {return this.currentPrice;}

}

class StockService2 {
	static float getChangePercent(int previousClosingPrice, int currentPrice) {
		return (((float) currentPrice / previousClosingPrice) - 1) * 100;
	}
}








